const config = require('./config');
const signalr = require('@aspnet/signalr');
const logger = require('./logs/logger');

let _connection = new signalr.HubConnectionBuilder()
    .withUrl(config.hubOpt.adb)
    .configureLogging(signalr.LogLevel.Information)
    .build();

module.exports = {

    get connection() {
        return new Promise((resolve, reject) => {
            if (_connection.state == signalr.HubConnectionState.Disconnected) {
                _connection.start()
                    .then(() => {
                        resolve(_connection)
                    })
                    .catch(reject)
            } else {
                resolve(_connection)
            }
        });
    }
};